package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {
    /**
     *  分页查询
     * @param studentQueryParam
     * @return
     */
    Page<Student> pageQuery(StudentQueryParam studentQueryParam);
/**
 *  批量删除
 */
    void deleteByIds(List<Integer> ids);

    /**
     *  新增
     * @param student
     */
    void insert(Student student);

    /**
     *  根据id查询
     * @param id
     * @return
     */
    Student getById(Integer id);

    /**
     *  修改
     * @param student
     */
    void update(Student student);

    /**
     * 记录违规信息
     *
     * @param id 用户ID，用于标识用户
     * @param score 违规分数，表示用户违规行为的严重程度
     */
    @Update("update student set violation_count=violation_count+1, violation_score=violation_score+#{score} where id=#{id}")
    Integer updateViolation(@Param("id") Integer id, @Param("score") Integer score);


    /**
     *  查询各学历人数
     * @return
     */
    @MapKey("degree")
    List<Map> countStuDegreeData();

    /**
     *  查询各班级人数
     * @return
     */
    @MapKey("pos")
    List<Map<String, Object>> countStudentData();

    void insertBatch(List<Student> studentList);

    @Delete("delete from student where id=#{id}")
    void deleteById(Integer id);

    @Select("select count(*) from student where clazz_id=#{clazzId} limit 1")
    Integer existsWithClazzId(Integer clazzId);
}
